package com.ita.controller;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ita.pojo.Customer;
import com.ita.service.CustomerManger;
import com.ita.service.impl.CustomerMangerFactory;

@RestController
@RequestMapping(value = "/customers")
public class CustomerController {

	private CustomerManger manager;

	public CustomerController() {

		manager = CustomerMangerFactory.getInstance();
	}

	@RequestMapping(value = "/add", method = RequestMethod.PUT)
	public List<Customer> addCustomer(@RequestBody Customer c) {

		manager.addCustomer(c);
		List<Customer> customers = manager.findAllCustomers();
		return customers;
	}

	@RequestMapping(value = "/listAll", method = RequestMethod.GET)
	public List<Customer> findAllCustomers() {

		List<Customer> customers = manager.findAllCustomers();
		return customers;
	}
	
	@RequestMapping(value = "/get", method = RequestMethod.POST)
	public Customer getCustomer(@RequestBody String id) {

		Customer c = manager.getCustomer(id);
		return c;
	}

	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public List<Customer> updateCustomer(@RequestBody Customer c) {

		manager.updateCustomer(c);
		List<Customer> customers = manager.findAllCustomers();
		return customers;
	}

	@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
	public List<Customer> deleteCustomer(@RequestBody String id) {

		manager.deleteCustomer(id);
		List<Customer> customers = manager.findAllCustomers();
		return customers;
	}

}
